package banking.domain;

public class CheckingAccount extends Account {
    private double overdraftProtection;

    public CheckingAccount(double balance) {
        super(balance);
    }

    public CheckingAccount(double balance, double protect) {
        super(balance);
        this.overdraftProtection = protect;
    }

    public void withdraw(double amt) throws OverdraftException {
        if (balance >= amt) {
            balance -= amt;

        } else if (balance + overdraftProtection >= amt) {
            overdraftProtection -= (amt - balance);
            balance = 0;

        } else {
            if (overdraftProtection == 0) {
                throw new OverdraftException("no overdraft protection", amt - balance);

            } else {
                throw new OverdraftException("Insufficient funds for overdraft protection", amt);
            }
        }
    }
}
